package com.cxf.windex.entity.vo;


import com.cxf.windex.base.util.CommonUtil;
import com.cxf.windex.base.util.TimeUtils;
import lombok.Data;

import java.util.Date;

/**
 * 微信支付信息
 */
@Data
public class WxInfo {
    private String appid;

    private String body;
    private String mch_id;
   // private String device_info; //设备号，小程序传"WEB"
    private String nonce_str;

    private String notify_url;

    private String out_trade_no;

    private String spbill_create_ip;

    private int total_fee;

    private String trade_type; //交易类型,JSAPI
    private String sign;
    //private String sign_type;  //签名类型
    //private String detail;
   // private String attach
  //  private String time_start;
  //  private String time_expire
  //  private String limit_pay;  //指定支付方式，no_credit

    /**
     * 生成付款信息
     * @param clientIP IP地址
     * @param randomNonceStr 随机数
     * @param timeformat 时间格式
     * @param timeexpire 过期天数
     * @param appid appid
     * @param mchid 商户号
     * @param notifyUrl 回调地址
     * @return
     */
    public WxInfo createInfo( String clientIP, String randomNonceStr, String timeformat, int timeexpire
            , String appid, String mchid, String notifyUrl) {

        Date date = new Date();
        String timeStart = TimeUtils.getFormatTime(date, timeformat);
        String timeExpire = TimeUtils.getFormatTime(TimeUtils.addDay(date, timeexpire), timeformat);

        String randomOrderId = CommonUtil.getRandomOrderId();

        WxInfo payInfo = new WxInfo();
        payInfo.setAppid(appid);
        payInfo.setMch_id(mchid);
        //payInfo.setDevice_info("WEB");
        payInfo.setNonce_str(randomNonceStr);
       // payInfo.setSign_type("MD5");
        payInfo.setBody("小象电商-购买商品");
       // payInfo.setAttach("shopPay");
        payInfo.setOut_trade_no(randomNonceStr);
        payInfo.setTotal_fee(1);
       payInfo.setSpbill_create_ip(clientIP);
      //  payInfo.setTime_start(timeStart);
      //  payInfo.setTime_expire(timeExpire);
        payInfo.setNotify_url(notifyUrl);
        payInfo.setTrade_type("APP");
       // payInfo.setLimit_pay("no_credit");
        return payInfo;
    }
}
